package cn.itcast.bos.web.action.take_delivery;

import cn.itcast.bos.domain.take_delivery.Order;
import cn.itcast.bos.service.take_delivery.OrderService;
import cn.itcast.bos.web.action.common.BaseAction;
import com.opensymphony.xwork2.ActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 *
 * @author: SOS
 * @create: 2018-03-06 16:09
 */

@ParentPackage("json-default")
@Namespace("/")
@Controller
@Scope("prototype")
public class OrderAction extends BaseAction<Order> {

    @Autowired
    private OrderService orderService;

    //通过ordernum查找order
    @Action(value = "order_findByOrderNum",results = {@Result(name = SUCCESS,type = "json"),
            @Result(name = "input",location = "./index.html",type = "redirect")})
    public String findByOrderNum(){

        Map<String,Object> map = new HashMap<String, Object>();
        Order existOrder = orderService.findByOrderNum(model.getOrderNum());
        if (existOrder != null) {
            map.put("success",true);
            map.put("orderData",existOrder);
        }else {
            map.put("success",false);
        }
        ActionContext.getContext().getValueStack().push(map);

        return SUCCESS;
    }
}
